﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TextMining
{
    public class Document  // Dataset's single document
    {
        public int WordCount { private set; get; }  // number of words in document
        public int Id { private set; get; }   // document's number
        public SortedList<string, Pair> Words { private set; get; }   // set of <Word, times of appearance>

        public Document(int id)
        {
            Words = new SortedList<string, Pair>();
            WordCount = 0;  // no words at the beginning
            Id = id;  // document's number
        }

        public void AddWord ( Word word )   // one more word in document
        {
            if (word.CurrentDocument != this || word.CurrentDocument == null)
                Words[word.Name] = new Pair(word, 1);   // word is not in the set
            else
                Words[word.Name].Value++;   // word is in the set --> one more appearance

            WordCount++;   // one more word in set
        }

        public void RemoveWord ( Word word )
        {
            int oldCount = Words.Count;
            Words.Remove(word.Name);   // remove word

            WordCount -= oldCount - Words.Count;   // one less word if this word is in the set
        }
    }

    public class Pair   // pair of <word, times of appearance>
    {
        public Word Key { set; get; }   // word
        public int Value { set; get; }  // times of appearance

        public Pair(Word key, int value)
        {
            Key = key;
            Value = value;
        }
    }
}
